package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

/**
 * @author Neuedu-远哥
 * @version 1.0
 * @date 2021/12/3 9:07
 */
public class Item extends AbstractMapleStoryObject {

    public int qty;

    public Item() {
        this.qty = 1;
    }

    public Item(MapleStoryClient msc, int x, int y, int type) {
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.type = type;
        this.img = getImage(type);
        this.width = img.getWidth(null);
        this.height = img.getHeight(null);
        this.jump = true;
        this.drop = false;
    }

    private Image getImage(int type) {
        Image img = null;
        switch (type) {
            case 1:
                img = ImageUtil.getImageByKey("HP_50");
                break;
            case 2:
                img = ImageUtil.getImageByKey("HP_150");
                break;
            case 3:
                img = ImageUtil.getImageByKey("HP_300");
                break;
            case 4:
                img = ImageUtil.getImageByKey("HP_MP_50%");
                break;
            case 5:
                img = ImageUtil.getImageByKey("HP_MP_100%");
                break;
            case 6:
                img = ImageUtil.getImageByKey("money");
                break;
            default:
                break;
        }
        return img;
    }

    @Override
    public void draw(Graphics g) {

        if(!live){
            msc.items.remove(this);
            return;
        }

        g.drawRect(msc.background.x + x,y,width,height);
        g.drawImage(img,msc.background.x + x,y,null);
        if(jump){
            jump(msc.grounds);
        }else{
            jumpDown(msc.grounds);
        }
    }
}
